
new Vue({

    data:{
        //视频类别
        types:[],
        currentTypeId : 0,
        videos: [],
        paginate:{},
        loading:false
    },

    filters:{
        textOverflow: function(value, length){
            if( value.length > length ){
                return value.substring(0,length) +"..."
            }else{
                return value
            }
        }
    },

    methods:{
        getVideoList:function(page){
            var self = this;
            self.loading=true;
            page = page || 1;
            var p =  self.$http.get('/api/web-page/video?video_type_id='+self.currentTypeId+'&per_page=18&page='+page).then(function(response){
                return response.json();
            }).catch(function(error){
                throw error;
            });

            p.then(function(result){
                if( result.code !== 0 ){
                    throw new Error( "请求视频列表失败，错误号："+result.code );
                }
                self.videos = result['videos_paginate'].data;
                self.paginate = result['videos_paginate'];
                self.loading=false;

                setTimeout(function () {
                    [].forEach.call(document.getElementsByTagName('video'), (v)=>v.load());
                },500);
            });

        },

        changeType:function(id){
            this.currentTypeId = Number(id);
            this.getVideoList();
        },

        changePage:function(number){
            this.getVideoList(number)
        },

        alertIndex:function (i) {
            alert(i);
        }

    },

    mounted:function(){

        //请求分类
        //this.getTypes();

        //请求列表数据
        this.getVideoList();

    },

    components:{
        bymPagination:bymPagination
    }

}).$mount("#video");


